package com.learn.reflectTest;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectTest {

    //获取类反射的四种方式
    @Test
    public void testLei() throws Exception {
        Class<Person> personClass = Person.class;
        Constructor<Person> declaredConstructor = personClass.getDeclaredConstructor(int.class, String.class);
        Person p = declaredConstructor.newInstance(11, "男");
        Field age = personClass.getDeclaredField("age");
        Method show = personClass.getDeclaredMethod("show", int.class);
        age.setAccessible(true);
        age.set(p,13);
        System.out.println(p.toString());
    }
}
